﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace _03WPF交互控件与图形
{
	/// <summary>
	/// Window1.xaml 的交互逻辑
	/// </summary>
	public partial class Window1 : Window
	{
		// 定义 ObservableCollection 集合，存储 MyItem 类型的数据
		public ObservableCollection<MyItem> MyItems { get; set; }

		public Window1()
		{
			InitializeComponent();

			// 初始化集合并添加数据
			MyItems = new ObservableCollection<MyItem>
		{
			new MyItem { Text = "第一项" },
			new MyItem { Text = "第二项" },
			new MyItem { Text = "第三项" },
			new MyItem { Text = "第四项" },
			new MyItem { Text = "第五项" }
		};

			// 将当前窗口（或ViewModel）设为数据上下文，使XAML能绑定到 MyItems
			DataContext = this;
		}
	}

	// 简单的数据模型类，存储每个项的文本
	public class MyItem
	{
		public string Text { get; set; } // 用于显示的文本属性

		public override string ToString()
		{
			return Text.ToString();
		}
	}
}
